package com.budwk.app.sqfwV2.generator.propagandaScreening;


import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfwDoc.codeGenerator.pdfGenerate.SqfwPdfCreateCommonBO;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.CompleteFlowBusinessParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.PdfGenerateParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.generate.BasePdfGenerator;
import com.budwk.app.sqfwV2.dto.PropagandaScreeningDTO;
import com.budwk.app.sqfwV2.dto.dulaying.DuLaYingPropagandaOrScreeningPdfDTO;
import com.budwk.app.sqfwV2.dto.dulaying.ScreeningHiddenDTO;
import com.budwk.app.util.ClassUtil;
import com.budwk.app.util.poiUtils.CommonFormOfficeUtils;
import com.deepoove.poi.data.PictureRenderData;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class PropagandaScreeningPdfGenerator extends BasePdfGenerator {

    private String templateName;
    private String theme;
    private ScreeningHiddenDTO screeningHiddenDTO;
    private String screeningSummarize;

    public void setScreeningSummarize(String screeningSummarize) {
        this.screeningSummarize = screeningSummarize;
    }
    public void setScreeningHiddenDTO(ScreeningHiddenDTO screeningHiddenDTO) {
        this.screeningHiddenDTO = screeningHiddenDTO;
    }
    private String propagandaInvestigationAndSummary;
    public PropagandaScreeningPdfGenerator(){}

    public void setTheme(String theme) {
        this.theme = theme;
    }

    public void setPropagandaInvestigationAndSummary(String propagandaInvestigationAndSummary) {
        this.propagandaInvestigationAndSummary = propagandaInvestigationAndSummary;
    }

    public PropagandaScreeningPdfGenerator(String templateName){
        this.templateName=templateName;
    }



    public String getTemplateName() {
        return this.templateName;
    }


    public boolean pdfCreateConditionCheck(SqfwPdfCreateCommonBO pdfDTO) {
        return false;
    }




    @Override
    protected boolean pdfCreateConditionCheck(PdfGenerateParam pdfGenerateParam) {
        return true;
    }

    @Override
    protected void customerPopularPdfParam(Map<String, Object> paramMap, PdfGenerateParam pdfGenerateParam) {
        CompleteFlowBusinessParam businessParam = (CompleteFlowBusinessParam) pdfGenerateParam.getBusinessParam();
        Sqfw_formSummary_new formSummary = businessParam.getFormSummary();
        PropagandaScreeningDTO propagandaScreeningDTO= JSON.parseObject(formSummary.getParamData(), PropagandaScreeningDTO.class);
        paramMap.put("theme",this.theme);
        paramMap.put("propagandaInvestigationAndSummary",this.propagandaInvestigationAndSummary);
        paramMap.put("screeningSummarize",this.screeningSummarize);
        // 图片处理
        String images = propagandaScreeningDTO.getImages();
        String fieldName = ClassUtil.getField(DuLaYingPropagandaOrScreeningPdfDTO::getImages);
        List<String> pictureUrlList = images == null ? Arrays.asList("") : Arrays.asList(images.split(","));
        List<Map<String, PictureRenderData>> pictures = CommonFormOfficeUtils.addWordPicture(pictureUrlList, fieldName, 6.0F);
        paramMap.put(fieldName + "s", pictures);
        if(ObjUtil.isNotEmpty(screeningHiddenDTO)){
            if(screeningHiddenDTO.getWhetherThereIsAnyHiddenDanger()){
                propagandaScreeningDTO.setWhetherThereIsAnyHiddenDanger("是");
            }else {
                propagandaScreeningDTO.setWhetherThereIsAnyHiddenDanger("否");
            }

        }
        paramMap.put("whetherThereIsAnyHiddenDanger",propagandaScreeningDTO.getWhetherThereIsAnyHiddenDanger());
    }


    @Override
    protected String getTemplatePath(PdfGenerateParam pdfGenerateParam) {
        return this.templateName;
    }





}
